package com.cosw.sdkShanghaiCA;

/**
 * Created by zhanglinhua on 2017/8/8.
 */

public enum EnumError {
  FAILED(0, "执行失败"),
  SUCCESS(1, "执行成功"),
  SPACE_NOT_ENOUGH(2, "空间不够"),
  SPACE_LOCKED_FOREVER(3, "永久锁定"),
  TIMEOUT(4, "超时失败"),
  INVALID_PARAMETER(5, "参数错误"),

  BLE_NOT_INITIAL(6, "蓝牙未初始化"),
  DEVICE_NOT_EXIST(7, "设备不存在"),
  NOT_BLE_SIM(8, "设备不是蓝牙SIM卡"),
  AUTH_FAILED(9, "设备认证失败"),
  NOT_SUPPORT_BLE(10, "手机不支持BLE"),
  NOT_IMPL_METHOD(11, "未实现接口"),
  TRANSMIT_TIMEOUT(12, "与蓝牙key通信超时，请检查连接是否正常"),

  NO_LOGIN(1001, "未登录"),
  NO_FOUND_ALG_ERROR(1002, "没有匹配的算法"),
  KEY_TYPE_ERROR(1003, "没有匹配的密钥用途"),
  CERT_INVALID(1004, "证书非法"),
  CERT_SAVE_EXCEPTION(1005, "签名证书存储异常"),
  KEY_PIN_INVALID(1006, "PIN无效"),
  KEY_PIN_NO_MATCH(1007, "PIN不正确"),
  KEY_NO_INIT(1008, "登录Key未初始化"),
  KEY_PIN_LOCKED(1009, "登录Key已锁"),
  ENV_NOT_INIT(1010, "环境未初始化"),
  EVENT_SET_ERROR(1011, "环境初始化失败"),
  DATA_LENGTH_ERROR(1012, "算法长度错误"),
  PRIVATE_KEY_FORMAT_ERROR(1013, "私钥格式错误"),
  PUBLIC_KEY_FORMAT_ERROR(1014, "公钥格式错误"),
  CERT_FORMAT_ERROR(1015, "证书格式错误"),
  SIGN_CRYP_ERROR(1016, "签名运算底层错误"),
  PKCS10_REQEUSET_ERROR(1017, "Ｐ10请示错误"),
  IO_STORE_ERROT(1018, "Key IO 存储异常"),

  INPUT_PARAM_NULL_OR_INVALID(1020, "输入参数非法或为空"),
  NO_MATCH_ALIAS(1021, "没有找到匹配的容器别名"),
  DIS_ALG_TYPE_ERROR(1022, "非对称密钥算法标识有误"),
  DISGEST_ALG_TYPE_ERROR(1023, "摘要算法标识有误"),
  SYM_ALG_TYPE_ERROR(1024, "对称算法标识有误"),
  DIS_CIPHER_INVALID(1025, "非对称运算发生错误"),
  P12_INVALID(1026, "P12文件非法"),

  CREATE_CONTAINER_ERROR(1027, "创建容器失败");

  private final int resCode;
  private final String resDesc;

  EnumError(int resCode, String resDesc) {
    this.resCode = resCode;
    this.resDesc = resDesc;
  }

  public int getResCode() {
    return resCode;
  }

  public String getResDesc() {
    return resDesc;
  }

  /**
   * 根据code获取对应的名称
   */
  public static String getEnumName(int code) {
    for (EnumError item : EnumError.values()) {
      if (item.getResCode() == code) {
        return item.resDesc;
      }
    }
    return "";
  }
}
